"""
对服务端的响应封装
"""
from flask import jsonify


def ok(message="成功", data=None):
    return Res(Code().success, message, data)()


def err(message="错误", data=None):
    return Res(Code().err, message, data)()


class Res:
    def __init__(self, code: int, message: str, data: dict):
        self.code = code
        self.message = message
        self.data = data

    def __call__(self):
        return jsonify({
            'code': self.code,
            'message': self.message,
            "data": self.data
        })


class Code:
    success = 200
    err = 400
